from pymt import *
class MTButtonsZone(MTRectangularWidget):

  def __init__(self, type, parent, **kwargs):
	self.zone=parent
	if(type=='text'):
		kwargs.setdefault('cls', 'buttonsZoneText')	
		self.import_button=MTImageButton(filename="resources/graphics/textImport.png", scale=0.8, pos=((self.zone.width/2)-80,0))
		self.edit_button=MTImageButton(filename="resources/graphics/textEdit.png", scale=0.8, pos=((self.zone.width/2)-40,0) )
		self.close_button=MTButtonZone(filename="resources/graphics/textClose.png", scale=0.8, pos=((self.zone.width/2),0), parent=self.zone )
		self.lock_button=MTImageButton(filename="resources/graphics/textLock.png", scale=0.8, pos=((self.zone.width/2)+40,0) )
	else:
		kwargs.setdefault('cls', 'buttonsZoneMedia')		
		self.import_button=MTImageButton(filename="resources/graphics/mediaImport.png", scale=0.8, pos=((self.zone.width/2)-80,0) )
		self.edit_button=MTImageButton(filename="resources/graphics/mediaEdit.png", scale=0.8, pos=((self.zone.width/2)-40,0) )
		self.close_button=MTButtonZone(filename="resources/graphics/mediaClose.png", scale=0.8, pos=((self.zone.width/2),0), parent=self.zone  )
		self.lock_button=MTImageButton(filename="resources/graphics/mediaLock.png", scale=0.8, pos=((self.zone.width/2)+40,0) )

	super(MTButtonsZone, self).__init__(**kwargs)
	self.height=40	
	
	self.add_widget(self.import_button)
	self.add_widget(self.edit_button)
	self.add_widget(self.close_button)
	self.add_widget(self.lock_button)	
	
  def on_transform(self, angle, scale, trans, point):
	self.import_button.x=(self.width/2)-80
	self.edit_button.x=(self.width/2)-40
	self.close_button.x=(self.width/2)
	self.lock_button.x=(self.width/2)+40
	
  def on_release(self, touch):
    # if the touch isn't on the widget we do nothing
	if not self.collide_point(touch.x, touch.y):
		return False 

	
  def on_press(self, touch):
	# if the touch isn't on the widget we do nothing
	if not self.collide_point(touch.x, touch.y):
		return False
		
  def on_touch_move(self, touch):
	# if the touch isn't on the widget we do nothing
	if not self.collide_point(touch.x, touch.y):
		return False

  def draw(self):
    MTRectangularWidget.draw(self)


class MTButtonZone(MTImageButton):
  def __init__(self, parent, **kwargs):
	self.zone=parent 
	super(MTButtonZone, self).__init__(**kwargs)	
  def on_touch_up (self, touch):
	if not self.collide_point(touch.x, touch.y):
		MTImageButton.on_touch_up(self, touch)
		return False  
	self.zone.delete(touch)